package com.rephilo.proxy.interceptor;

import com.rephilo.proxy.ProxyTransaction;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * cglib代理流程
 *
 * @author rephilo
 */
public class CglibProxyInterceptor implements MethodInterceptor {

    private Object realObject;

    private ProxyTransaction proxyTransaction = new ProxyTransaction();

    @Override
    public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
        //此处可使用职责链模式改造，解析每一个注解
        return proxyTransaction.doMethodInvokeWithTransaction(realObject, method, args);
    }

    public CglibProxyInterceptor(Object realObject) {
        this.realObject = realObject;
    }
}
